import { reactive, ref } from 'vue'
import axios from '../plugins/axios'
import router from '../plugins/router'

export default () => {
   interface SvgCaptha {
      key: string
      svg: string
   }

   const form = reactive({
      username: '',
      password: ''
   })

   const svgCaptha = ref<ResponseTypes<SvgCaptha>>()
   const getSvgCaptha = async () => {
      svgCaptha.value = await axios.request<SvgCaptha>({
         url: '/svgCaptcha'
      })
   }

   const login = () => {
      return axios.request<{ token: string }>({
         url: 'auth/login',
         method: 'POST',
         data: form
      })
   }

   const register = () => {
      return axios.request({
         url: 'auth/register',
         method: 'POST',
         data: form
      })
   }

   return { getSvgCaptha, svgCaptha, form, login, register }
}
